home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / string.arc / TXTFMT.PAS < prev   
Pascal/Delphi Source File  |  1991-04-28  |  1KB  |  40 lines

  1. program testformat;
  2. uses crt,strings;
  3. const maxlines=10;
  4. var s:array [1..maxlines] of string;
  5.     t1:string;
  6.     i,len,lins,p:byte;
  7.  
  8. begin
  9.     i:=0;
  10.     writeln('This program will accept up to 10 lines of text and print it');
  11.     writeln('out as a right- and left-justified paragraph.');
  12.     repeat
  13.        inc(i);
  14.        writeln('Enter line ',i,', or a null to end input: '); readln(s[i]);
  15.        s[i]:=space(s[i],1);
  16.     until (s[i]='') or (i=maxlines) ;
  17.     if s[i]='' then dec(i);
  18.     lins:=i;
  19.     len:=30;
  20.     while len<80 do begin
  21.        writeln(copies('----+',len div 5));
  22.        i:=0; t1:='';
  23.        while i<lins do begin
  24.           while (length(t1)<=len) and (i<lins) do begin
  25.              inc(i);
  26.              t1:=t1+s[i]+' ';
  27.           end;
  28.           while length(t1)>len do begin
  29.              p:=lastpos(' ',t1,len+1);
  30.              writeln(justify(left(t1,p,' '),len));
  31.              t1:=right(t1,length(t1)-p,' ');
  32.           end;
  33.        end;
  34.        writeln(t1);
  35.        writeln('Press enter to continue ...'); readln;
  36.        len:=len+20;
  37.     end;
  38. end.
  39.  
  40.